#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 3e4 + 10, M = 1e5 + 10;
int tree[M];
int l[N], r[N];
int w[N];
int n;
int lowbit(int x)
{
	return x & -x;
}

void add(int x, int v)
{
	for (int i = x; i <= M - 1; i+=lowbit(i)) {
		tree[i] += v;
	}
}

int query(int x)
{
	int ans = 0;
	for (int i = x; i; i -= lowbit(i)) {
		ans += tree[i];
	}
	return ans;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		l[i] = query(w[i] - 1);
		add(w[i], 1);
	}
	memset(tree, 0, sizeof(tree));
	/*for (int i = 1; i <= n; i++) {
		cout << tree[i] << endl;
	}*/
	//cout << query(5) << endl;
	for (int i = n; i >= 1; i--) {
		//cout << query(M - 1) << endl;
		r[i] = query(M - 1) - query(w[i]);
		add(w[i], 1);
	}
	for (int i = 1; i <= n; i++) {
		//cout << "i==" << i << "   l[i]==" << l[i] << "    r[i]==" << r[i] << endl;
		ans += (LL)(l[i] * r[i]);
	}
	cout << ans << endl;
	return 0;
}